<template>
  <div class="deviceMetrics">
    <div class="box" v-for="item in items " :key="item.deviceId">
      <div class="label" v-if="item.level == 0"><span class="hov">{{ item.online ? '正常' : '离线' }} </span></div>
      <div class="label" v-if="item.level != 0"><span class="hov">{{ item.level == 1 ? '一般报警' : '严重报警' }}</span></div>
      <div class="title">{{ item.deviceId }}</div>
      <div class="content">
        <div class="row" v-for="(it, ind) in item.quotaList" :key="ind">
          <div class="key">{{ it.quotaName }} {{ it.value }}{{ it.unit }}</div>
          <div class="value">正常值 &nbsp; {{ it.referenceValue }} {{ it.unit }}</div>
        </div>
      </div>
      <div class="more" @click="openDetailsHandle(item)">...</div>
    </div>
    <!--    用于填充    -->
    <div class="box" v-for="index of 4" :key="index" style="background-color: #FFF;height: 0px"/>

    <el-dialog v-model="DialogVisible" title="设备指标" width="30%" center>
      <div class="dialog-content">
        <div v-for="(it, ind) in itemData.quotaList" class="row" :key="ind">
          <span>{{it.quotaName}} &nbsp;<i style="color:#999" :class="{lab: it.level != 0}"> {{it.value}} {{it.unit}}</i> </span>
          <span style="color:#818693">正常值 &nbsp; {{it.referenceValue}} {{it.unit}} </span>
        </div>
      </div>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="DialogVisible = false">Cancel</el-button>
      </span>
      </template>
    </el-dialog>
  </div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component'
import { device } from '@/api/device'
@Options({})
export default class deviceMetrics extends Vue {
  private itemData = {}
  private DialogVisible = false

  data: any = null
  items: any = null
  public openDetailsHandle (item:any) :void{
    this.itemData = item
    this.DialogVisible = true
    console.log('kkk')
  }

  private async getList () {
    this.data = await device({
      // page: this.page,
      // pageSize: this.pageSize,
      // ...this.formInline
    })

    this.items = this.data.items
  }

  mounted () {
    this.getList()
  }
}
</script>
<style lang="scss" scoped>
.deviceMetrics{
  display: flex;
  //width: 100%;
  //height: 100%;
  //height: calc(100vh - 170px);
  flex-wrap: wrap;
  justify-content: space-between;

}
//.deviceMetrics::after{
//  content: '';
//  flex: auto;
//  min-width: 0px;
//}
.box{
  height: 166px;
  //width: calc(20% - 20px);
  margin: 10px;
  background-color: #F2F2F2;
  //width: calc((100% - 40px) / 5);
  //min-width: calc((100% - 40px) / 5);
  min-width: 265px;
  max-width: calc((100% - 100px) / 5);
  border-radius: 11px;
  flex-grow: 2;
  //&:nth-child(5n) {
  //  margin-right: 0;
  //}
  .label{
    display: flex;
    justify-content: center;
    margin: 15px 0;
  }
  .title{
    display: flex;
    justify-content: center;
    margin: 15px 0;
  }
  .content{
    display: flex;
    min-height: 38px;
    .row{
      display: flex;
      justify-content: space-between;
      margin: 10px 5px;
      .key .value{
        display: flex;
      }
    }
  }

  .more{
    display: flex;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
    line-height: 0px;
    cursor: pointer;
    color: #5584FF;
    margin: 15px 0;
    align-self: flex-end;
  }
}
.dialog-content{
  padding: 0px 80px;
  .row{
    justify-content: space-between;
    display: flex;
    margin: 10px 5px;
    .key{
      display: flex;
    }
    .value{
      display: flex;
    }
  }
}
</style>
